package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Report;
import com.tanhua.domain.vo.AnswersVo;
import com.tanhua.domain.vo.QuestionnaireVo;
import com.tanhua.domain.vo.ReportVo;
import com.tanhua.server.service.SoulTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author HoshizoraL
 * @Date 2021/4/20 10:40
 */
@RestController
@RequestMapping("/testSoul")
public class SoulTestController {

    @Autowired
    private SoulTestService soulTestService;

    @GetMapping
    public ResponseEntity questionnaireList() {
        List<QuestionnaireVo> voList = soulTestService.questionnaireList();
        return ResponseEntity.ok(voList);
    }

    @GetMapping("/report/{id}")
    public ResponseEntity getReport(@PathVariable("id") String id){
        ReportVo reportVo = soulTestService.getReport(id);
        return ResponseEntity.ok(reportVo);
    }

    @PostMapping
    public ResponseEntity uploadTest(@RequestBody Map<String, List<AnswersVo>> param){
        List<AnswersVo> answers = (List<AnswersVo>) param.get("answers");
        String id = soulTestService.getReportId(answers);
        return ResponseEntity.ok(id);
    }
}
